<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>用户登录</title>
     <link rel="stylesheet" type="text/css" href="../css/amazeui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
     <link rel="stylesheet" type="text/css" href="../css/tngou.css" />
</head>
<body>


<div class="am-g">

<div  class="am-form am-margin"  >
  
  
    <legend class="am-text-center   am-text-danger">新用户注册 </legend>
    <div class="am-input-group am-form-group am-input-group-danger">
     <span class="am-input-group-label"><i class="am-icon-envelope-o am-icon-fw"></i></span>
      <input type="email" id="email" name="email"  placeholder="输入邮件" class="am-form-field" required/>
    </div>
    
    <div class="am-input-group am-form-group am-input-group-danger">
     <span class="am-input-group-label"><i class="am-icon-at am-icon-fw"></i></span>
      <input type="text" id="account" name="account"  placeholder="输入昵称" class="am-form-field" required/>
    </div>
 
     <div class="am-input-group am-form-group am-input-group-danger">
     <span class="am-input-group-label"><i class="am-icon-lock am-icon-fw"></i></span>
      <input type="password" id="password" name="password"  placeholder="输入最少6位的登录密码" class="am-form-field" required/>
    </div>
    <div class="am-form-group">
    <button class="am-btn am-btn-danger am-radius am-btn-block" type="button" onclick="reg();" >注册新用户</button>
    <p class="am-text-sm am-text-secondary">如果你不是天狗网注册用户，请点击这里进行用户注册，就可以实现相关操作</p>
    </div>
    <hr>
  
 
 
</div>
</div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/jquery.min.js"></script>
<script src="../script/amazeui.min.js"></script>
<script src="../script/config.js"></script>
<script type="text/javascript">
  var client_id,client_secret;
	apiready = function(){
		
		    client_id = API_client_id;
        	client_secret= API_client_secret;
 
	};

function reg()
{
	      var email=$("#email").val();
	        if(!checkValue(email,Match.email))
		     {
		     	$("#email").focus();
		       api.toast({msg : '请输入正确的邮箱，不能为空'});
	           return;
		     }
		     
		      var account=$("#account").val();
	        if(!checkValue(account,Match.account))
		     {
		     	$("#account").focus();
		       api.toast({msg : '请输入正确英文名称，不能为空'});
	           return;
		     }
     
		     var password=$("#password").val();
	         if(!checkValue(password,Match.password))
		     {
		     	$("#password").focus();
		       api.toast({msg : '请输入正确登录密码，6-16位'});
	           return;
		     }
		     
		      api.showProgress({
			    style: 'default',
			    animationType: 'fade',
			    title: '注册中...',
			    text: '请稍候...',
			    modal: false
			});
			     
		     api.ajax({
			    url: OpenAPI.oauth_reg,
			    method: 'post',
			    dataType: 'json',
			    returnAll:false,
			    data:{
			        values: {account: account,email: email,password: password,client_id:client_id,client_secret:client_secret}
			    }
			},function(ret,err){
			    
			    if(ret.status)
			    {
			      
					 var access_token=ret.access_token;
			          $api.setStorage('access_token', ret.access_token);	// 设置cookie
			          
			           api.ajax({
			              url: OpenAPI.user,
			              method: 'post',
			              dataType: 'json',
			              data:{
					        values: {access_token: access_token}
					    	}
					    },function(ret,err){
					     
                           // api.alert({msg: JSON.stringify(ret)});
                           api.hideProgress();
					    	if(ret.status)
					    	{					    	   
						       api.setPrefs({
								    key: 'user',
								    value: ret
								});	
								api.closeWin();															
								
							}		              
					              
					     }); 
						
			    }else
			    {
			        api.hideProgress();
			        api.toast({msg : ret.msg});		    
			    }
			    
			});

}
	
	function showUser(url,name)
	{	
	    api.openFrame({
	            name: name,
	            showProgress:true,
	            url: url,
	            bounces: false,	
	            reload:true,        
	            rect: {
	                x: 0,
	                y: 58,
                    w: 'auto',
                    h: api.winHeight-108
	            }
	        }); 	
		
	
	}		
	

</script>
</html>